package cn.chinaunicom.sdsi.upfc_demp.jyxx.service.impl;

import cn.chinaunicom.sdsi.upfc_demp.demo.entity.UpfDemoTest;
import cn.chinaunicom.sdsi.upfc_demp.demo.service.UpfDemoTestService;
import cn.chinaunicom.sdsi.upfc_demp.jyxx.dao.mybatis.JyXxMapper;
import cn.chinaunicom.sdsi.upfc_demp.jyxx.entity.JyXx;
import cn.chinaunicom.sdsi.upfc_demp.jyxx.service.JyXxService;
import cn.chinaunicom.sdsi.upfc_demp.demo.dao.mybatis.UpfDemoTestMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.chinaunicom.sdsi.frm.base.BaseService;
import com.github.pagehelper.PageInfo;
import java.util.List;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Service
public class JyXxServiceImpl extends BaseService implements JyXxService{

	@Autowired
	private JyXxMapper jyXxMapper;
	/**
	 * 分页查询
	 */
	@Override
	public JSONObject search4PageList(UpfDemoTest upfDemoTest,Integer start, Integer length){
		setPageInfo(start,length);
		List<UpfDemoTest> beanList=jyXxMapper.search4PageList(upfDemoTest);
		PageInfo<UpfDemoTest> page = new PageInfo<UpfDemoTest>(beanList);
		JSONObject obj = null;
		JSONArray array = new JSONArray();
		
		for(UpfDemoTest bl :beanList){
			obj = new JSONObject();
					obj.put("id",bl.getId());
					obj.put("name",bl.getName());
					obj.put("author",bl.getAuthor());
					obj.put("status",bl.getStatus());
					obj.put("createTime",bl.getCreateTime());
			array.add(obj);
		}
		obj = new JSONObject();
		obj.element("data", array);
		obj.element("recordsTotal", page.getTotal());
		obj.element("recordsFiltered", page.getTotal());
		obj.element("draw", 0);
		return obj;
	}
	
	/**
	 * 查询单条数据
	 */
	@Override
	public JyXx selectByPrimaryKey(JyXx jyXx){
		
	    JyXx bean=jyXxMapper.selectByPrimaryKey(jyXx);
		return bean;
	}
	
	/**
	 * 删除单条数据
	 */
	@Override
	public int deleteByPrimaryKey(JyXx jyXx){
		int delnum = jyXxMapper.deleteByPrimaryKey(jyXx);
		return delnum;
	}

	/**
	 * 保存数据
	 */
	@Override
	public int addObject(UpfDemoTest upfDemoTest){
		int insertnum = jyXxMapper.addObject(upfDemoTest);
		return insertnum;
	}

	/**
	 * 修改单条数据
	 */
	@Override
	public int updateByPrimaryKey(UpfDemoTest upfDemoTest){
		int updatetnum = jyXxMapper.updateByPrimaryKey(upfDemoTest);
		return updatetnum;
	}


}